package net.cherrylab.war.view
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.Shape;
	import flash.events.Event;
	import flash.geom.Point;
	
	import mx.events.FlexEvent;
	
	public class Hexagon extends Shape
	{
		private var _baseX:Number;
		private var _baseY:Number;
		//private var _radius:Number=100;
		public static const ANGLE:Number=Math.PI/3;
		public var cp:Point;    //中心点
		public var enp:Point;   //东北点
		public var esp:Point;   //东南点
		public var wnp:Point;    //西北点
		public var wsp:Point;     //西南点
		public var ep:Point;      //东点
		public var wp:Point;      //西点
		
		public var bmp:BitmapData;
		
		
		public function Hexagon(_r:Number)
		{
			init(_r);
			
			//addEventListener(FlexEvent.CREATION_COMPLETE, onDraw);
		}
		
		private function init(r:Number):void
		{
			_baseX=this.x+r;
			_baseY=this.y+Math.sin(Hexagon.ANGLE)*r;
			//确定每个点的位置
			cp=new Point(_baseX,_baseY);
			wsp=new Point(_baseX-(Math.cos(ANGLE)*r),_baseY+(Math.sin(ANGLE)*r));
			esp=new Point(_baseX+(Math.cos(ANGLE)*r),_baseY+(Math.sin(ANGLE)*r));
			ep=new Point(_baseX+r,_baseY);
			wp=new Point(_baseX-r,_baseY);
			wnp=new Point(_baseX-(Math.cos(ANGLE)*r),_baseY-(Math.sin(ANGLE)*r));
			enp=new Point(_baseX+(Math.cos(ANGLE)*r),_baseY-(Math.sin(ANGLE)*r));
			graphics.moveTo(wnp.x,wnp.y);
			graphics.lineStyle(1);
			bmp=this.onDraw();
		}
		
		public function onDraw():BitmapData
		{
			//绘制六条边
			graphics.lineTo(enp.x,enp.y);
			graphics.lineTo(ep.x,ep.y);
			graphics.lineTo(esp.x,esp.y);
			graphics.lineTo(wsp.x,wsp.y);
			graphics.lineTo(wp.x,wp.y);
			graphics.lineTo(wnp.x,wnp.y);
			
			var bd:BitmapData=new BitmapData(this.width,this.height,true,0);
			bd.draw(this);
			
			return bd;
		}// end function
	}
}